
package com.dream.launcher;

import com.dream.zhujianjun.R;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.FrameLayout;

public class MainLayout extends FrameLayout {

    private Drawable mDrawable;
    private Bitmap mBitmap;
    
    private Workspace mWorkspace;
    int screenWidth;
    int screenHeight;
    
    private final WallpaperManager mWallpaperManager;

    public MainLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MainLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mDrawable = getResources().getDrawable(R.drawable.galaxy_thumb);
        mWallpaperManager = WallpaperManager.getInstance(context);
        Drawable draw =  mWallpaperManager.getDrawable();
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        int start = getWidth();
        if(mWorkspace != null) 
            start = mWorkspace.getCurScreen()*getWidth();
        Bitmap showBitmap = Bitmap.createBitmap(mBitmap,start,0,getWidth(),getHeight()); 
        canvas.drawBitmap(showBitmap, 0, 0, null);
        super.dispatchDraw(canvas);
    }

    public void setWorkspace(Workspace wkspace) {
        mWorkspace = wkspace;
    }
}
